<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.shsh.safemanage.dao.UserDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.Role"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.action.UserAction"%>
<%@page import="com.shsh.safemanage.model.Department2"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>

<%
{
DepartmentDao theDepartmentDao = DaoCreator.createDepartmentDao();
UserDao theUserDao = DaoCreator.createUserDao();
User theLoginUser = (User) session.getAttribute(Constants.SESSION_USER);
List<Department2> theDepart2List = theDepartmentDao.getDepartment2ListByDepartment1ID(theLoginUser.getDepartment1ID());

UserAction theCheckUserAction = ActionCreator.createUserAction();

Role checkUserRole = theCheckUserAction.getUserRole(request);
if ((checkUserRole.getRoleType() & (Constants.ROLE_TYPE_CHUZHANG)) > 0) {
	Department2 leaderDepart2 = new Department2();
	leaderDepart2.setId(0L);
	leaderDepart2.setDepartment2Name("管理层");
	leaderDepart2.setKeshi(true);
	theDepart2List.add(leaderDepart2);
}
%>
<table style="margin-left: 20px" border="0" cellpadding="0" cellspacing="0">
	<%
	boolean isBreak = false;
	for (int i = 0; i < 1000; i++) {
		if (isBreak) {
			break;
		}
	%>
	<tr>
	<%
		int k = 0;
		int j = 0;
		while (true) {
			int index = i * 5 + j;
			if (index >= theDepart2List.size()) {
				isBreak = true;
				break;
			}
			j++;
			Department2 depart2 = theDepart2List.get(index);
			if (!depart2.isKeshi()) {
				continue;
			}
			k++;
			if (k > 5) {
				break;
			}
	%>
		<td width="140" style="border-bottom:1px #E3E3E3 dashed;border-right:1px #E3E3E3 dashed;" valign="top">
		<a style="margin: 5px" href="javascript:" onclick="changeDisplayStatus('keshiUserDiv<%=depart2.getId()%>')"><%=depart2.getDepartment2Name()%></a>
		<div id="keshiUserDiv<%=depart2.getId()%>" style="display: none">
		<table>
		<%
			if (depart2.getId() > 0) {
				List<User> depart2Users = theDepartmentDao.getUsersByDepartment2ID(depart2.getId(), true, 
						Constants.ROLE_TYPE_KEYUAN | Constants.ROLE_TYPE_FUKEZHANG);
				boolean mnIsBreak = false;
				for (int n = 0; n < 1000; n++) {
					if (mnIsBreak) {
						break;
					}
		%>
			<tr>
			<%
				for (int m = 0; m < 2; m++) {
					int mnIndex = n * 2 + m;
					if (mnIndex >= depart2Users.size()) {
						mnIsBreak = true;
						break;
					}
				
					User depart2User = depart2Users.get(mnIndex);
			%>
				<td valign="middle">
				<input type="checkbox" name="informedUserID" value="<%=depart2User.getId()%>" style="margin: 2px" />
				<span><%=depart2User.getName()%></span>
				</td>
			<%
				}
			%>
			</tr>
			<%
				}
			} else {
				List<User> leaderUserList = theUserDao.getUsersByRoleType(theLoginUser.getDepartment1ID(), Constants.ROLE_TYPE_FUCHUZHANG);
				boolean mnIsBreak = false;
				for (int n = 0; n < 1000; n++) {
					if (mnIsBreak) {
						break;
					}
			%>
			<tr>
			<%
				for (int m = 0; m < 2; m++) {
					int mnIndex = n * 2 + m;
					if (mnIndex >= leaderUserList.size()) {
						mnIsBreak = true;
						break;
					}
				
					User depart2User = leaderUserList.get(mnIndex);
			%>
				<td valign="middle">
				<input type="checkbox" name="informedUserID" value="<%=depart2User.getId()%>" style="margin: 2px" />
				<span><%=depart2User.getName()%></span>
				</td>
			<%
				}
			%>
			</tr>
		<%
				}
			}
		%>
		</table>
		</div>
		</td>
	<%
		}
	%>
	</tr>
	<%
	}
	%>
</table>
<%
}
%>